package com.atguigu.springcloud.controller;

import cn.hutool.core.util.IdUtil;
import com.atguigu.springcloud.service.PaymentService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * hystrix 测试类
 * http://localhost:8001/payment/hystrix/timeout/1
 */
@RequestMapping("payment/hystrix")
@RestController
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService service;

    @Value("${server.port}")
    private String serverPort;

    // =======以下服务都是服务降级
    @GetMapping("/ok/{id}")
    public String payment_ok(@PathVariable("id") Integer id){
        String result = service.paymentInfoOk(id);
        log.info("result=="+result);
        return result;
    }

    @GetMapping("/timeout/{id}")
    public String payment_timeout(@PathVariable("id") Integer id){
        String result = service.paymentInfoTimeOuT(id);
        log.info("result=="+result);
        return result;
    }



    //===== 服务熔断
    @GetMapping("/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id) {
        String result = service.paymentCircuitBreader(id);
        log.info("***result："+result);
        return result;
    }
}
